package cn.wolfcode.controller;

import cn.wolfcode.domain.Result;
import cn.wolfcode.util.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {
@Autowired
    private OSSUtil ossUtil;
@PostMapping("/upload")
    public Result sentImage(MultipartFile image) throws IOException {
    String contentType = image.getContentType();
    if (!contentType.endsWith("jpeg"))
    {
        return  Result.error("图片的类型只能是jpg");
    }
    else
    {
        String upload = ossUtil.getURL(image);
        return  Result.success(upload);
    }
}
}
